package com.block.merchant.service.impl;

import com.block.db.entity.MerchantBaseInfo;
import com.block.db.entity.MerchantDataCountInfo;
import com.block.db.mapper.MerchantBaseInfoMapper;
import com.block.db.mapper.MerchantDataCountInfoMapper;
import com.block.merchant.service.IMerchantDataCountInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 商户数据统计 服务实现类
 * </p>
 *
 * @author 
 * @since 2023-12-19
 */
@Service
public class MerchantDataCountInfoServiceImpl extends ServiceImpl<MerchantDataCountInfoMapper, MerchantDataCountInfo> implements IMerchantDataCountInfoService {

    @Resource
    MerchantBaseInfoMapper merchantBaseInfoMapper;

    @Override
    public void tempCount(String dateInfo){

        List<Integer> infoIdList = this.baseMapper.selectMerchantInfo(dateInfo);

        for (Integer infoId : infoIdList) {

            MerchantBaseInfo merchantBaseInfo = merchantBaseInfoMapper.selectById(infoId);

            MerchantDataCountInfo dataCountInfo = new MerchantDataCountInfo();
            dataCountInfo.setInfoId(merchantBaseInfo.getId());
            dataCountInfo.setInfoName(merchantBaseInfo.getInfoName());
            dataCountInfo.setDateInfo(dateInfo);

            // 查询拿到链接的数据
            Integer urlNumber = this.baseMapper.countUrlNumber(infoId, dateInfo);
            dataCountInfo.setUrlNumber(urlNumber);
            // 查询打开链接的数据
            Integer clickNumber = this.baseMapper.countClickNumber(infoId, dateInfo);
            dataCountInfo.setClickNumber(clickNumber);

            // 查询结算的数据
            Integer successNumber = this.baseMapper.countSuccessNumber(infoId, dateInfo);
            dataCountInfo.setSuccessNumber(successNumber);

            boolean save = this.save(dataCountInfo);

        }

    }

}
